<?php

defined( 'IN_CLASS' ) or die( 'Access Error!' );

class ModelSms extends base {
	
	//获得我的所有的小纸条
	function getall( $uid ) {
		$sql = "SELECT t1.*,t2.name FROM $this->tsms t1,$this->tmember t2 WHERE t1.to='{$uid}' AND t1.from=t2.id";
		$aSms = model::dbuser()->get_all( $sql );
		return is_array( $aSms ) ? $aSms : array();
	}
	
	//检查当前有没有小纸条
	function checknew( $id ) {
		$sql = "select 1 from $this->tsms where `to`='{$id}' LIMIT 1";
		model::dbuser()->exe( $sql );
		return model::dbuser()->select_rows();
	}
	
	//删除小纸条,只有接收方可以丢弃小纸条，接收后就删除了
	function sms_del ( $uid ) {
		$sql = "DELETE FROM $this->tsms WHERE `to`='{$uid}'";
		model::dbuser()->exe( $sql );
		return model::dbuser()->update_rows();
	}
	
	function send( $from, $to, $content ) {
		$sql = "INSERT INTO $this->tsms SET `from`='{$from}',`to`='{$to}',content='{$content}',time=now()";
		model::dbuser()->exe( $sql );
		return model::dbuser()->update_rows();
	}
}